home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / tkern10.zip / SRC\TDEVICE.C < prev    next >
Text File  |  1994-06-04  |  3KB  |  131 lines

  1. /*
  2.  *  This file forms part of "TKERN" - "Troy's Kernel for Windows".
  3.  *
  4.  *  Copyright (C) 1994  Troy Rollo <troy@cbme.unsw.EDU.AU>
  5.  *
  6.  *  This library is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU Library General Public
  8.  *  License as published by the Free Software Foundation; either
  9.  *  version 2 of the License, or (at your option) any later version.
  10.  *
  11.  *  This library is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  *  Library General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU Library General Public
  17.  *  License along with this library; if not, write to the Free
  18.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #include <string.h>
  22. #include <errno.h>
  23. #include <sys/tdevice.h>
  24.  
  25. extern    int    nError;
  26.  
  27. #pragma argsused
  28. static    long
  29. invalid_seek(    int    id,
  30.         long    loc,
  31.         int    from)
  32. {
  33.     nError = EINVAL;
  34.     return -1;
  35. }
  36.  
  37. extern    int    window_open(    char const *,
  38.                 int,
  39.                 int);
  40. extern    int    window_close(    int);
  41. extern    int    window_read(    int,
  42.                 char *,
  43.                 int);
  44. extern    int    window_write(    int,
  45.                 char const *,
  46.                 int);
  47. extern    int    window_ioctl(    int,
  48.                 struct    tk_ioctl *);
  49.                 
  50.  
  51. extern    int    pipe_open(    char const *,
  52.                 int,
  53.                 int);
  54. extern    int    pipe_close(    int);
  55. extern    int    pipe_read(    int,
  56.                 char *,
  57.                 int);
  58. extern    int    pipe_write(    int,
  59.                 char const *,
  60.                 int);
  61. extern    int    pipe_ioctl(    int,
  62.                 struct    tk_ioctl *);
  63.                 
  64.  
  65. extern    int    file_open(    char const *,
  66.                 int,
  67.                 int);
  68. extern    int    file_close(    int);
  69. extern    long    file_seek(    int,
  70.                 long,
  71.                 int);
  72. extern    int    file_read(    int,
  73.                 char *,
  74.                 int);
  75. extern    int    file_write(    int,
  76.                 char const *,
  77.                 int);
  78. extern    int    file_ioctl(    int,
  79.                 struct    tk_ioctl *);
  80.                 
  81.  
  82. struct    tdevice    dev_list[] =
  83. {
  84.     {
  85.     window_open,    invalid_seek,    window_read,    window_write,
  86.     window_close,    window_ioctl,    "window",    DF_TTY,    /* 00 */
  87.     },
  88.  
  89.     {
  90.     file_open,    file_seek,    file_read,    file_write,
  91.     file_close,    file_ioctl,    "file",        0    /* 01 */
  92.     },
  93.  
  94.     {
  95.     pipe_open,    invalid_seek,    pipe_read,    pipe_write,
  96.     pipe_close,    pipe_ioctl,    "pipe",        0,    /* 02 */
  97.     },
  98.  
  99. };
  100.  
  101. int    num_devs = sizeof(dev_list) / sizeof(dev_list[0]);
  102.  
  103.  
  104. int
  105. get_device_number(char const *pchDevice)
  106. {
  107.     int    i;
  108.     char    achDevice[256];
  109.     char    const *c;
  110.  
  111.     c = strchr(pchDevice, '/');
  112.     if (c)
  113.     {
  114.         if (c - pchDevice >= 256)
  115.             return -1;
  116.         strncpy(achDevice, pchDevice, c - pchDevice);
  117.         achDevice[c - pchDevice] = 0;
  118.     }
  119.     else
  120.     {
  121.         strcpy(achDevice, pchDevice);
  122.     }
  123.  
  124.     for (i = 0; i < num_devs; i++)
  125.     {
  126.         if (!strcmp(achDevice, dev_list[i].devname))
  127.             return i;
  128.     }
  129.     return 0;
  130. }
  131.